package com.lqian.deep_clone;



/**
 * 深克隆测试
 * @author：Melody_LQ
 * @time：2022/9/1 10:10 下午
 */
public class DeepCloneTest {

    public static void main(String[] args) throws CloneNotSupportedException {
       Student student = new Student(1,"Jack");
        //原型对象
        Teacher teacher = new Teacher(student,18);
        //克隆
        Teacher clone = teacher.clone();
        //生成对象，结果为false，说明两个student对象指向不同的内存地址
        System.out.println(teacher.getStudent() == clone.getStudent());

        //赋克隆对象的值
        //通过修改其中一个对象的属性值，结果其中一个对象的属性值发生变化，
        // 说明两个student对象指向不同的内存地址
        clone.getStudent().setAge(3);
        System.out.println(teacher);
        System.out.println(clone);
        System.out.println("原型对象和克隆对象是否相等:"+(teacher == clone));
    }
}
